/*
 * Copyright (c) 2011-2014, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: sendFunction.c 7805 2014-03-13 09:54:35Z geisinger $
 */

/**
 * \file
 *         Source file for function send in component sender.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (XMT)
 *         (fortiss GmbH).
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "queues/adv/sender/include/sendFunction.h"

#include "queues/adv/sender/include/sendFunctionWrapper.h"
#include "queues/adv/sender/include/senderComponent.h"
#include "queues/adv/sender/include/senderComponentWrapper.h"
#include "queues/adv/sender/include/senderManifest.h"

#include "xme/core/logUtils.h"

// PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_C_INCLUDES) ENABLED START

#include "queues/topic/dictionary.h"

// PROTECTED REGION END

/******************************************************************************/
/***   Definitions                                                          ***/
/******************************************************************************/

// PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_C_DEFINITIONS) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Variables                                                            ***/
/******************************************************************************/
/**
 * \brief  Variable holding the value of the required output port 'out'.
 *
 * \details If necessary initialize this in the init function.
 *          The value of this variable will be written to the port at the end of
 *          the step function.
 */
static queues_topic_data_t
portOutData;

// PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_C_VARIABLES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/

// PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_C_PROTOTYPES) ENABLED START

// PROTECTED REGION END

/******************************************************************************/
/***   Implementation                                                       ***/
/******************************************************************************/
xme_status_t
queues_adv_sender_sendFunction_init
(
    queues_adv_sender_senderComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_INITIALIZE_C) ENABLED START
    
    XME_CHECK(NULL != componentConfig, XME_STATUS_INVALID_PARAMETER);
    
    return XME_STATUS_SUCCESS;
    
    // PROTECTED REGION END
}

void
queues_adv_sender_sendFunction_step
(
    queues_adv_sender_senderComponent_config_t* const componentConfig
)
{
    xme_status_t status[1];
    
    queues_topic_data_t* portOutDataPtr = &portOutData;
    
    {
        // PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_STEP_C) ENABLED START

        static uint32_t value = 0;
        uint8_t senderID  = componentConfig->instanceNumber;

        XME_UNUSED_PARAMETER(status);

        portOutData.value = value++;

        queues_adv_sender_senderComponentWrapper_writeOutputPortAttribute
        (
            QUEUES_ADV_SENDER_SENDERCOMPONENTWRAPPER_PORT_OUT,
            (xme_core_attribute_key_t)QUEUES_ATTRIBUTE_SENDER,
            &senderID,
            sizeof(senderID)
        );

        XME_LOG(XME_LOG_NOTE, "[sender %hhu] Sending value: %u\n", senderID, portOutData.value);
        
        // PROTECTED REGION END
    }
    
    status[0] = queues_adv_sender_senderComponentWrapper_writePortOut(portOutDataPtr);
    
    {
        // PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_STEP_2_C) ENABLED START
        
        // Nothing to do
        
        // PROTECTED REGION END
    }
}

void
queues_adv_sender_sendFunction_fini
(
    queues_adv_sender_senderComponent_config_t* const componentConfig
)
{
    // PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_TERMINATE_C) ENABLED START
    
    // Nothing to do
    
    XME_UNUSED_PARAMETER(componentConfig);
    
    // PROTECTED REGION END
}

// PROTECTED REGION ID(QUEUES_ADV_SENDER_SENDFUNCTION_IMPLEMENTATION_C) ENABLED START

// PROTECTED REGION END
